﻿@model SILAS.Entidades.SAP
        
@{
    ViewBag.Title = "AsignarSap";
    Layout = "~/Views/Shared/_layoutGeneral.cshtml";
}

@if (false)
{ 
    <script src="../../Scripts/jquery-1.8.2-vsdoc.js" type="text/javascript"></script>
}
           
<script type="text/javascript">

    $(function () {

        var Sap;
        var _idSector = @ViewBag.iid;

        $("#txtBuscarSap").autocomplete({

            source: '@Url.Action("GetSAPbycrit", "SAP" , new {idSector = @ViewBag.iid})',
            minLength: 1,
            focus: function (event, ui) {
                var select = ui.item;
                $("#txtBuscarSap").val(select.label);
                return false;
            },
            select: function (event, ui) {
                var select = ui.item;
                $("#txtBuscarSap").val(select.label);
                Sap = select.Sap;
                $("#idSap").val(select.value);
                return false;
            }
        });


        $("#add2").click(function (e) {
            e.preventDefault();

            var _id = $("#idSap").val();

            $.post('@Url.Action("AsignarSAP", "SAP")',
                    { idSap: _id , idsector: _idSector},
                         function (ok) {
                             if (ok) {
                                 if (ok.exito == true) {
                                     alert(ok.msg);
                                     window.location = '@Url.Action("Index", "SAP")'+'/index/'+@ViewBag.iid;
                                 }
                                 else {
                                     alert(ok.msg);
                                 }
                             }
                         }, "json");
        });

    });
</script>

@using (Html.BeginForm())
{ 
<fieldset>
    <legend> Asignar SAP</legend>
    <div id='center' class='ui-widget ui-corner-all' style='float:left;width:60%;margin-top:0.5em;margin-left:0.5em;'>
       
            
            <div class="ui-widget-content ui-corner-bottom" style="padding:0.5em;">
        
            @Html.Label("Buscar SAP:")
            @Html.TextBox("txtBuscarSap")
            @Html.Hidden("idSap")

           
            <button id="add2">Añadir SAP</button>
            </div>
      </div>
     <div>
       <center><b>SAPs Asignadas</b></center>
              @Html.ListBox("SapID")
      </div>


</fieldset>

}

<a href="@Url.Action("Index", "SAP", new { id = @ViewBag.iid })">
			   <img src="@Url.Content("~/Content/Imagenes/volver.jpg")" title="Volver a Listar SAP" alt="Volver a Listar SAP" />
			</a>


